cssprovider: Keep only the curent section while parsing
authorBenjamin Otte <otte@redhat.com>
Fri, 17 Jun 2011 02:52:43 +0000 (04:52 +0200)
committerBenjamin Otte <otte@redhat.com>
Fri, 26 Aug 2011 14:26:27 +0000 (16:26 +0200)
We don't need a list of sections, the section can give us the parent
when we need it (d'oh).

gtk/gtkcssprovider.c

index 1c5ed95623330379687e4cd044b4a3b1ee6c4753..be93730829cf3cf9c9f359a68f10fadccc9fa7ce 100644 (file)
@@ -965,7 +965,7 @@ struct _GtkCssScanner
 {
   GtkCssProvider *provider;
   GtkCssParser *parser;
-  GSList *sections;
+  GtkCssSection *section;
   GtkCssScanner *parent;
   GFile *file;
   GFile *base;
@@ -1219,8 +1219,6 @@ gtk_css_ruleset_matches (GtkCssRuleset *ruleset,
 static void
 gtk_css_scanner_destroy (GtkCssScanner *scanner)
 {
-  g_assert (scanner->sections == NULL);
-
   g_object_unref (scanner->provider);
   if (scanner->file)
     g_object_unref (scanner->file);
@@ -1247,6 +1245,7 @@ gtk_css_scanner_parser_error (GtkCssParser *parser,
 static GtkCssScanner *
 gtk_css_scanner_new (GtkCssProvider *provider,
                      GtkCssScanner  *parent,
+                     GtkCssSection  *section,
                      GFile          *file,
                      const gchar    *data,
                      gsize           length)
@@ -1260,6 +1259,8 @@ gtk_css_scanner_new (GtkCssProvider *provider,
   g_object_ref (provider);
   scanner->provider = provider;
   scanner->parent = parent;
+  if (section)
+    scanner->section = gtk_css_section_ref (section);
 
   if (file)
     {
@@ -1305,34 +1306,33 @@ static void
 gtk_css_scanner_push_section (GtkCssScanner     *scanner,
                               GtkCssSectionType  section_type)
 {
-  GtkCssSection *parent, *section;
-
-  if (scanner->sections)
-    parent = scanner->sections->data;
-  else if (scanner->parent)
-    parent = scanner->parent->sections->data;
-  else
-    parent = NULL;
+  GtkCssSection *section;
 
-  section = _gtk_css_section_new (parent,
+  section = _gtk_css_section_new (scanner->section,
                                   section_type,
                                   scanner->parser,
                                   scanner->file);
-  scanner->sections = g_slist_prepend (scanner->sections, section);
+
+  gtk_css_section_unref (scanner->section);
+  scanner->section = section;
 }
 
 static void
 gtk_css_scanner_pop_section (GtkCssScanner *scanner,
                              GtkCssSectionType check_type)
 {
-  GtkCssSection *section = scanner->sections->data;
+  GtkCssSection *parent;
   
-  g_assert (check_type == gtk_css_section_get_section_type (section));
+  g_assert (gtk_css_section_get_section_type (scanner->section) == check_type);
+
+  parent = gtk_css_section_get_parent (scanner->section);
+  if (parent)
+    gtk_css_section_ref (parent);
 
-  scanner->sections = g_slist_delete_link (scanner->sections, scanner->sections);
+  _gtk_css_section_end (scanner->section);
+  gtk_css_section_unref (scanner->section);
 
-  _gtk_css_section_end (section);
-  gtk_css_section_unref (section);
+  scanner->section = parent;
 }
 
 static void
@@ -2520,7 +2520,12 @@ gtk_css_provider_load_internal (GtkCssProvider *css_provider,
 
   if (data)
     {
-      scanner = gtk_css_scanner_new (css_provider, parent, file, data, length);
+      scanner = gtk_css_scanner_new (css_provider,
+                                     parent,
+                                     parent ? parent->section : NULL,
+                                     file,
+                                     data,
+                                     length);
 
       parse_stylesheet (scanner);